package com.It;

import java.util.Scanner;

public class PrintDigitalTriangle {

    public static void printZTriangle(int n) {
        int[] a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        int m = n;
        for (n = 1; n < m + 1; n++) {
            //输出空格
            for (int i = 0; i < 9 - n; i++) {
                System.out.print(" ");
            }
            //输出左边数字
            for (int f = 1; f < n; f++) {
                System.out.print(a[f]);
            }
            //输出中间数字
            System.out.print(a[n]);
            //输出右边数字
            for (int b = n - 1; b > 0; b--) {
                System.out.print(a[b]);
            }
            //输出一层后换行
            System.out.println();
        }
    }

    public static void printDTriangle(int n) {
        int[] c = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        int m = n;
        for (n = 9; n > 9 - m; n--) {
            //输出空格
            for (int i = 8; i > n-1; i--) {
                System.out.print(" ");
            }
            //输出左边数字
            for (int f = 1; f <  n ; f++) {
                System.out.print(c[f]);
            }
            //输出中间数字
            System.out.print(c[n]);
            //输出右边数字
            for (int b = n-1; b >0 ; b--) {
                System.out.print(c[b]);
            }
            //输出一层后换行
            System.out.println();


        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要打印的三角形的层数：");
        int n = sc.nextInt();
        if (n == 0 || n > 9) {
            System.out.println("超出范围，请输入1-9之间的数字");
        } else {
            System.out.println("正数字三角形如下：");
            printZTriangle(n);
            System.out.println("------------------");
            System.out.println("倒数字三角形如下：");
            printDTriangle(n);
        }

    }
}
